<?php
/**
 * 优惠券领取情况查询接口【申请】 jd.union.open.coupon.query
 *
 * See: https://union.jd.com/openplatform/api/762
 * User: Ken.Zhang <kenphp@yeah.net>
 * Date: 2019-05-12
 */
class UnionOpenCouponQueryRequest {

    /**
     * 优惠券链接集合；上限10（GET请求）；上限50（POST请求或SDK调用）
     */
    private $couponUrls;

    /**
     * 请求参数
     */
    public $apiParams = [];

    public function setCouponUrls($url)
    {
        $this->couponUrls = $url;
        $this->apiParams['couponUrls'] = $url;
    }

    public function getCouponUrls()
    {
        return $this->couponUrls;
    }

    public function getApiMethodName()
    {
        return 'jd.union.open.coupon.query';
    }

    /**
     * 解析结果
     *
     * @param   string      $response
     * @throws  Exception
     * @return  mixed
     */
    public function getResult($response)
    {
        $responseKey = str_replace('.', '_', $this->getApiMethodName()) . '_response';

        $response = @json_decode($response, true);
        if (!array_key_exists($responseKey, $response))
            $resp = $response['errorResponse'];
        else {
            $response[$responseKey]['result'] = json_decode($response[$responseKey]['result']);

            $resp = $response[$responseKey];
        }

        return $resp;
    }

}